package ui;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

import colors.Color;

import model.trajectory.TargetModel;

public class TargetGridModel extends AbstractTableModel 
{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1995442386876186340L;
	public ArrayList<TargetModel> targets;
	public String[] columnNames = new String[] {"Target name", "", "Show"};
	
	public TargetGridModel(ArrayList<TargetModel> targets)
	{
		this.targets = targets;
	}
	@Override
	public int getColumnCount() {
		// TODO Auto-generated method stub
		return 3;
	}

	@Override
	public int getRowCount() {
		return targets.size();
	}

	@Override
	public Object getValueAt(int row, int col) 
	{
		if(col == 0)
		{
			return this.targets.get(row);
		}
		else if ( col == 1)
		{
			return this.targets.get(row).getColor();
		}
		else
		{
			return this.targets.get(row).isVisible();
			//return this.targets.get(row).isVisible;
		}
	}
	
    public void setValueAt(Object value, int row, int col) 
    {
    	if(col == 2)
    	{
    		targets.get(row).setVisible(! targets.get(row).isVisible());
    	}
        fireTableCellUpdated(row, col);
    }
	
	@SuppressWarnings("unchecked")
	@Override
	public Class getColumnClass(int col)
	{
		if(col == 0)
		{
			return TargetModel.class;
		}
		if(col == 1)
		{
			return Color.class;
		}
		if(col == 2)
		{
			return Boolean.class;
		}
		return null;
	}
	
	public boolean isCellEditable(int row, int col)
	{
		if(col == 2)
		{
			return true;
		}
		return false;
	}
	
	public String getColumnName(int col) 
	{  
		return columnNames[col];
	}
}
